package Env;

import java.util.Vector;

public class State {
	
	private int position;
	private Vector<Car>[] vertexes;
	private Car car;
	private State papa;
	private float work;
	
	public State(int pos,Vector<Car>[] vertexes){
		basicConstructor(pos, vertexes);
		car=null;
		papa=null;
		work=0;
	}

	public State(State s, Integer j, Car car) {
		basicConstructor(j,s.getVertexes());
		vertexes[s.position].remove(car);
		vertexes[j].add(car);
		this.car=car;
		papa=s;
		work=s.getWork();
		Main.Main.log.fine("created state at vertex "+j+" with car "+car);
//		System.out.println("state at vertex " + j + " created with cars ");
	//	for (int i=0; i < vertexes[j].size(); i++)
		//	System.out.println(vertexes[j].elementAt(i));
	}

	public int getPosition() {
		return position;
	}

	public Vector<Car>[] getVertexes() {
		return vertexes;
	}
	
	private void basicConstructor(int pos, Vector<Car>[] vertexes) {
		this.position=pos;
		this.vertexes= new Vector[vertexes.length];
		for (int i=0; i<vertexes.length; i++){
			this.vertexes[i] = new Vector<Car>();
			for (Car car : vertexes[i]){
				this.vertexes[i].add(car);
			}
		}
	}

	public Car getCar() {
		return this.car;
	}

	public State getPapa() {
		return papa;
	}

	public void setWork(float f) {
		work+=f;
	}
	
	public float getWork(){
		return work;
	}
}
